package com.example.home.fragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.home.R;
import com.example.home.fragment.bean.NewsCommentBean;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.MyHoldy> {
    private Context context;
    private List<NewsCommentBean.RowsBean> list;

    public CommentAdapter(Context context, List<NewsCommentBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public CommentAdapter.MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_comlist,null);
        return new CommentAdapter.MyHoldy(view) ;
    }

    @Override
    public void onBindViewHolder(@NonNull CommentAdapter.MyHoldy holder, int position) {
        holder.tvName.setText(list.get(position).getUserName());
        holder.tvContent.setText(list.get(position).getContent());
        holder.tvLick.setText("点赞数:"+list.get(position).getLikeNum());
        holder.tvTime.setText(list.get(position).getCommentDate());
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : 15;
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private TextView tvName;
        private TextView tvContent;
        private TextView tvLick;
        private TextView tvTime;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
            tvContent = itemView.findViewById(R.id.tv_content);
            tvLick = itemView.findViewById(R.id.tv_lick);
            tvTime = itemView.findViewById(R.id.tv_time);

        }
    }
}
